package com.excilys.formation.project.services.impl;

import java.util.List;
import java.util.Map;

import org.joda.time.YearMonth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.excilys.formation.project.entities.Operation;
import com.excilys.formation.project.entities.TypeOperation;
import com.excilys.formation.project.repository.OperationDAO;
import com.excilys.formation.project.services.OperationService;

/**
 * 
 * @author excilys
 * 
 */
@Service
@Transactional(readOnly = true)
public class OperationServiceImpl implements OperationService {

    /**
     * Instance de l'OperationDAO pour le service.
     */
    @Autowired
    private OperationDAO operationDAO;

    @Override
    public List<Operation> getOperationsByCompteByYearMonth(String compteNumero, YearMonth mois) {
        return operationDAO.getOperationsByCompteAndTimeIntervalAndType(compteNumero, mois.toInterval(), null);
    }

    @Override
    public List<Operation> getOperationsByCompteByYearMonthAndType(String compteNumero, YearMonth mois, TypeOperation type) {
        return operationDAO.getOperationsByCompteAndTimeIntervalAndType(compteNumero, mois.toInterval(), type);
    }

    @Override
    public List<Operation> getOperationsByCompteByYearMonthExceptType(String compteNumero, YearMonth mois, TypeOperation type) {
        return operationDAO.getOperationsByCompteAndTimeIntervalExceptType(compteNumero, mois.toInterval(), type);
    }

    @Override
    public double getSumOperationsByCompteByYearMonthAndType(String compteNumero, YearMonth mois, TypeOperation type) {
        return operationDAO.getSumOperationsByCompteAndTimeIntervalAndType(compteNumero, mois.toInterval(), type);
    }

    @Override
    public double getSumEncoursByCompte(String compteNumero) {
        return operationDAO.getSumEncoursByCompte(compteNumero);
    }

    @Override
    public Map<String, Double> getSumEncoursByClient(long clientId) {
        return operationDAO.getSumEncoursByClient(clientId);
    }
}
